package cc.iits.demo.crane.web.controller;

import cc.iits.demo.crane.api.bo.biz.StatusBO;
import cc.iits.demo.crane.api.service.biz.StatusService;
import cc.iits.demo.crane.api.vo.RestResponse;
import cc.iits.demo.crane.web.support.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/v1/status")
public class StatusController {

    @Autowired
    private StatusService service;

    @PostMapping("/save")
    public RestResponse save(
            @RequestAttribute(Constants.SESSION_ID) String sid,
            @RequestBody StatusBO status
            ) {
        status.setSid(sid);
        service.save(status);
        return RestResponse.success();
    }

    @RequestMapping("/find")
    public RestResponse find(
            @RequestAttribute(Constants.SESSION_ID) String sid
    ) {
        return RestResponse.success().setData(service.find(sid));
    }
}
